package com.ruoyi.controller.jpjs.empchange;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.jpjs.PublicService;
import com.ruoyi.service.jpjs.empchange.EmpChangeService;
import com.ruoyi.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 人员异动表
 * author:zeo
 */

@Controller
@RequestMapping("/empChange")
public class EmpChangeController extends BaseController {

    @Autowired
    EmpChangeService empChangeService;

    private String prefix = "jpjs/empchange";


    @Autowired
    PublicService publicService;

    @GetMapping()
    public String empChange(ModelMap mmap) {
        mmap.put("userComp", publicService.findUserCompAndJszb());
        return prefix + "/empChange";
    }

    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map map) {
        startPage();
        return getDataTable(empChangeService.list(map));
    }

    @GetMapping("/add")
    public String add(ModelMap mmap) {
        mmap.put("userComp", publicService.findUserCompAndJszb());
        return prefix + "/add";
    }

    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestParam Map map) {
        return toAjax(empChangeService.add(map));
    }

    @GetMapping("/edit/{id}")
    public String edit(ModelMap mmap,@PathVariable("id") String id) {
        mmap.put("data",empChangeService.findDataById(id));
        mmap.put("userComp", publicService.findUserCompAndJszb());
        return prefix + "/edit";
    }

    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map) {
        return toAjax(empChangeService.edit(map));
    }

    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(empChangeService.remove(ids));
    }

    @RequestMapping("/findCompMonthIsNull")
    @ResponseBody
    public BaseResult findCompMonthIsNull(@RequestParam Map map){
        return empChangeService.findCompMonthIsNull(map);
    }

    /**
     * 根据年月取出月末人数
     * 用于在职人员分析(月末数据) 计算在职人员占比
     * @param map
     * @return
     */
    @RequestMapping("/findMonthEndNumByYearMonth")
    @ResponseBody
    public BaseResult findMonthEndNumByYearMonth(@RequestParam Map map){
        return empChangeService.findMonthEndNumByYearMonth(map);
    }

    /**
     * 根据年月取出当月离职总人数
     * 用于离职人员分析计算本月离职总人数
     * @param map
     * @return
     */
    @RequestMapping("/findQuitCountByYearMonth")
    @ResponseBody
    public BaseResult findQuitCountByYearMonth(@RequestParam Map map){
        return empChangeService.findQuitCountByYearMonth(map);
    }

}

